# -*- coding: utf-8 -*-
import datetime
import time
import aircv as ac
import os
import random


# 对比两张图，找到坐标。
def matchImg(imgsrc, imgobj):  # imgsrc=原始图像，imgobj=待查找的图片
    imsrc = ac.imread(imgsrc)
    imobj = ac.imread(imgobj)
    match_result = ac.find_template(imsrc, imobj,
                                    0.9)
    # 0.9、confidence是精度，越小对比的精度就越低 {'confidence': 0.5435812473297119,
    # 'rectangle': ((394, 384), (394, 416), (450, 384), (450, 416)), 'result': (422.0, 400.alipay_leave0)}
    if match_result is not None:
        match_result['shape'] = (imsrc.shape[1], imsrc.shape[0])  # 0为高，1为宽
    return match_result

# 截图
def screencap():
    try:
        # 截图
        os.popen('adb -s c49089c6 shell screencap -p /storage/emulated/0/Pictures/Screenshots/phoneScreencap.png')
        time.sleep(2)
        # print("截图")
        # 发送到电脑
        os.popen('adb -s c49089c6 pull /storage/emulated/0/Pictures/Screenshots/phoneScreencap.png')
        time.sleep(2)
    except Exception as e:
        print(e)
        print("截图异常")

screencap()